// index page
// ============

define(['require', 'zepto', 'sui', 'zeptoFx', 'zeptoTouch', 'submitForm'], function(require, JST) {
  return {
    init: function(data) {
      this.initPage();
      //this.initPicker(data.weeks);
      this.initSubmit();
    },
    
    initPage: function() {
      var that = this;
    },
    
    initPicker: function(weeks) {
      var that = this;
      var values = [], displayValues = [];
      
      for(var i = 0; i < weeks; i++) {
        values.push(i+1);
        displayValues.push((i+1)+"周")
      }
      
      $(".picker").picker({
        toolbarTemplate: '<header class="bar bar-nav">\
        <button class="button button-link pull-left">按钮</button>\
        <button class="button button-link pull-right close-picker">确定</button>\
        <h1 class="title">预计达成日期</h1>\
        </header>',
        cols: [
          {
            textAlign: 'center',
            values: values,
            displayValues: displayValues
          }
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find("[type='hidden']").val(value);
          return displayValue
        },
      });
      
    },
    
    initSubmit: function() {
      var that = this
      
      $(".save-button").on("click", function() {
        var flag = true;
        $(".edit-content-block input[type='text']").each(function(){
          console.log($(this).val());
          if(flag && $(this).val()) {
            if(isNaN($(this).val())) {
              $.toast("身体数据请输入数字");
              flag = false;
            }
          }
        })
        
        if(!flag) {
          return false;
        }
        
        $("[type='submit']").trigger("click")
      })
      
      $("form").submitform()
      
    }
  }
})